using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodePlex.SpaceBlock;
using CodePlex.Resourceful;
using System.Diagnostics;

namespace CodePlex.SpaceBlock.UI.Controls
{
    public partial class S3SettingsControl : BaseControl
    {
      
        public S3SettingsControl()
        {
            InitializeComponent();

            _lookupLink.Text = Properties.Messages.Options_S3_AmazonLookup;
        }

        public void Initialize(FileSystemInfo info)
        {
            Bind(_idBox, info.PublicSettings, UIConstants.S3Settings.AWSAccessKeyID);
            Bind(_secretKeyBox, info.PrivateSettings, UIConstants.S3Settings.AWSSecretAccessKey);
            Bind(_useSSLCheck, info.PublicSettings, UIConstants.S3Settings.UseSSL);
        }









        private void Bind(TextBox textbox, NameValuePairs nvp, string name)
        {
            textbox.Text = nvp.GetIfExists(name);
            textbox.TextChanged += delegate
            {
                nvp[name] = textbox.Text.Trim();
            };
        }

        private void Bind(CheckBox checkbox, NameValuePairs nvp, string name)
        {
            bool value;
            if (bool.TryParse(nvp.GetIfExists(name),out value)) 
            {
                checkbox.Checked = value;
            }
            checkbox.CheckedChanged += delegate
            {
                nvp[name] = checkbox.Checked.ToString();
            };
        }

        private void _lookupLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(Properties.Messages.Urls_AmazonLookup);
        }

       
    }
}

